<%@include file="/WEB-INF/views/includes/taglibs.jsp"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@include file="/WEB-INF/views/includes/adminHeader.jsp"%>



<!--[if gte IE 6]>
<script>
$(document).ready( function() {
$(".dataRow").mouseover(function(){$(this).addClass("dataRowOver");});
$(".dataRow").mouseout(function(){$(this).removeClass("dataRowOver");});
});
</script>
<![endif]-->
<script type="text/javascript">
function deleteUser(userId, name, email, sysGroupName, bizGroupName) {
	$("#deleteUserName").text(name);
	$("#deleteUserEmail").text(email);
	$("#deleteUserRole").text(sysGroupName);
	$("#deleteUserBizgroup").text(bizGroupName);
	$("#deleteUserId").val(userId);
	
	$('#deleteDialog').dialog('open');
}

function editUser(userId) {
	window.location.href = "<c:url value='/web/editUser?id='/>" + userId;
}

$(document).ready(
		function() {
			$('#deleteDialog').dialog({
				autoOpen: false,
				width: 400,
				draggable : true,
				resizable : false,
				dialogClass : 'deleteDialog',
				buttons: {
					"Yes, I'm sure": function() {
						userIdToBeDeleted = $("#deleteUserId").val();
						window.location.href = "<c:url value='/web/deleteUser?id='/>" + userIdToBeDeleted;
					},
					"No, I don't want": function() {
						$(this).dialog("close");
					}
				}
			});
		});
</script>
<div id="deleteDialog" title="Delete User">
	<h3>Confirm to delete? </h3>
	<input type="hidden" id="deleteUserId" name="deleteUserId"/>
	<div><span class="label">User Name:</span><span id="deleteUserName"></span></div>
	<div><span class="label">Email:</span><span id="deleteUserEmail"></span></div>
	<div><span class="label">Role:</span><span id="deleteUserRole"></span></div>
	<div><span class="label">Business Group:</span><span id="deleteUserBizgroup"></span></div>
	<br/>
</div>


<div class="homePage ui-tabs-panel ui-widget-content ui-corner-bottom">
	<div id="leftMenu">
		<%@include file="/WEB-INF/views/includes/userAdminLeftNav.jsp"%>
	</div>
	<div id="rightContent">
		<%@include file="/WEB-INF/views/includes/messages.jsp"%>
		<h2>User List</h2>
		<div class="searchBlock">
				<form:form method="post" action="userHome" id="searchUserform">
					<form:label path="userName">User Name</form:label>&nbsp;<form:input path="userName"/>&nbsp;&nbsp;
					<form:label path="sysGroup">User Role</form:label>&nbsp;
					<form:select path="sysGroup">
							<form:option value="0" label="All" />
							<form:options items="${sysGroups}"  itemValue="id" itemLabel="name" />
					</form:select>&nbsp;&nbsp;
					<form:label path="bizGroup">Business Group</form:label>&nbsp;
					<form:select path="bizGroup">
					        <form:option value="0" label="All" />
							<form:options items="${bizGroups}"  itemValue="id" itemLabel="name" />
					</form:select><br/>
					<button type="button"
						class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						onclick="save()" style="margin-top:5px">
						<span class="ui-button-text">Search User</span>
					</button>
					<script type="text/javascript">
						function save() {
							$('#searchUserform').submit();
						}
					</script>
				</form:form>
		</div>
		<div>
			<table class="generaltable" style="width:100%" cellspacing="0" cellpadding="0">
				<thead>
					<tr>
						<th>User Name</th>
						<th>Email</th>
						<th>User Role</th>
						<th>Business Group</th>
						<th>Operations</th>
					</tr>
				</thead>
				<tbody>
				<c:if test="${not empty userList}">
					<c:forEach items="${userList}" var="oneUser">
					<tr class="dataRow">
						<td>${oneUser.name}</td>
						<td>${oneUser.email}</td>
						<td>${oneUser.sysGroup.name}</td>
						<td>${oneUser.bizGroup.name}</td>
						<td><a href="#" onclick="editUser(${oneUser.id})">Edit</a>&nbsp;&nbsp;
						<a href="#" onclick="deleteUser(${oneUser.id}, '${oneUser.name}', '${oneUser.email}', '${oneUser.sysGroup.name}', '${oneUser.bizGroup.name}')">delete</a></td>
					</tr>
					</c:forEach>
				</c:if>
				</tbody>
			</table>
		</div>
		<div style="height:1px;width:740px;"></div>
	</div>
</div>

<%@include file="/WEB-INF/views/includes/adminfooter.jsp"%>